﻿using LD.Host;
using System.Collections.Generic;

namespace LD.PLC
{
    public static class PLCFactory
    {
        private static Dictionary<PLCType, PLCAbstract> _dicPLC = new Dictionary<PLCType, PLCAbstract>() {
            { PLCType.PansonCom,new PansonicSerial()},
            { PLCType.汇川H5U,new PlcInovanceH5u()},
            { PLCType.KeyenceTcp,new KeyenceTCP()},
            //{ PLCType.ModbusRtu,new ModbusCom()},
        };

        private static PLCAbstract _PLC;
        private static object _obj = new object();
        public static PLCType ActionPLC { get; set; }
        public static PLCAbstract Instance
        {
            get
            {
                if (_PLC == null)
                {
                    lock (_obj)
                    {
                        if (_PLC == null)
                        {
                            _PLC = _dicPLC[ActionPLC];
                        }
                    }
                }
                return _PLC;
            }
        }
    }
}
